import { locale, loading, modelService, GraphNode, Action, ActionKey, ModelValidateDegree, CheckElementsByRulesDto, rmi } from "@/mdesign-lib/mdesign-app.umd.js";


export class ValidateCurrentModelAction extends Action {
  keyName = ActionKey.ValidateCurrentModel;
  desc = "根据规则校验当前模型";

  async onTreeMenuClick(graphNode) {
    if (!graphNode) return;
    this.run(graphNode.id);
  }
  async run(modelId: string) {
    if (!app.activeProject) return;
    loading.popup(locale.t("校验中") + "...");
    const ruleInstanceIds = await modelService.queryValidationRuleInstanceIds({
      projectId: app.activeProjectId,
      severity: ModelValidateDegree.ERROR
    });
    const params = {
      projectId: app.activeProjectId,
      ruleInstanceIds,
      excludeReadOnly: false,
      instanceIds: [modelId],
      isCheckChildren: false,
      severity: ModelValidateDegree.ERROR
    } as CheckElementsByRulesDto;
    await rmi.invokeAction(ActionKey.checkElementsByRules, [JSON.parse(JSON.stringify(params))]);
    loading.close();
  }
}
